﻿// Copyright (c) Kona Framework Team. All rights reserved.
// For continued development and updates, visit http://www.codeplex.com/kona
// For a copy of the license please vist: http://www.codeplex.com/kona/license
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Kona.Data.Tests.Unit
{
    /// <summary>
    /// Summary description for AdoMdConnectionTest
    /// </summary>
    [TestClass]
    public class AdoMdConnectionTest
    {
        public AdoMdConnectionTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void Must_Get_Connection_From_ConnectionPool()
        {
            AdoMdConnection Connection = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW");
            Assert.IsNotNull(Connection);
        }

        [TestMethod]
        public void Must_Recycle_Connections_In_ConnectionPool()
        {
            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW"))
            {
                Assert.IsNotNull(Connection1);
            }

            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW"))
            {
                Assert.IsNotNull(Connection1);
            }
        }

        [TestMethod]
        public void Must_Get_Available_Connection_From_Pool()
        {
            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW"))
            {
                Assert.IsNotNull(Connection1);
                using (AdoMdConnection Connection2 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW"))
                {
                    Assert.IsNotNull(Connection2);
                    Assert.AreNotSame(Connection1,Connection2);
                }
            }
        }

        [TestMethod]
        public void Must_Open_Connection_To_OLAPDB()
        {
            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW"))
            {
                Connection1.Open();
                Assert.IsTrue(Connection1.State == System.Data.ConnectionState.Open );
            }            
        }

        [TestMethod]
        public void Must_Close_OpenConnection()
        {
            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW"))
            {
                Connection1.Open();
                Connection1.Close();
                Assert.IsTrue(Connection1.State == System.Data.ConnectionState.Closed);
            }
        }

    }
}
